package com.wwwc.admin.web.servlet;

import java.io.*;
import java.awt.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.ServletRequestWrapper;
import java.net.*;

import com.wwwc.util.web.*;

public class IndexServlet extends HttpServlet {
    public void doPost(HttpServletRequest request,  HttpServletResponse response) 
    {
	try {
	    response.setContentType("text/html");
	    HttpSession session   = request.getSession(true);
	    PrintWriter out       = response.getWriter();
	    String user_ip        = request.getRemoteAddr();
	    String selectedScreen = request.getServletPath();

	    String id  = request.getParameter("id");
	    if(id == null) {
		id = (String)session.getAttribute("id");
		if(id == null) {
		    id = "1";
		}
	    }

	    session.setAttribute("id",id);
	   
	    ResourceBundle config = (ResourceBundle)session.getAttribute("Configuration");
	
	    if (config == null) {
		Locale locale = request.getLocale();
		config = ResourceBundle.getBundle("Configuration", locale.getDefault()); 
		session.setAttribute("Configuration", config);
	    }

	    out.println("<HTML>");
	    out.println("<BODY>");
	    out.println("<HEAD>");
	    out.println("<TITLE></TITLE>");

	    out.println("<meta http-equiv=\"Content-Language\" content=\"en-us\">");
	    out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");

	    out.println("</HEAD>");
	    out.println("<table cellSpacing='0' cellPadding='0' border='1' align=center width=100%>");
	    out.println("<tr>");

	    if(id.equals("1")) {
		out.println("<td align=center><B>Databases</B></td>");
	    }
	    else {
		out.println("<td align=center><B><a href="+ request.getContextPath()+selectedScreen+"?id=1>Databases</a></B></td>");
	    }

	    if(id.equals("2")) {
		out.println("<td align=center><B>Accounts</B></td>");
	    }
	    else {
		out.println("<td align=center><B><a href=index?id=2>Accounts</a></B></td>");
	    }

	    if(id.equals("3")) {
		out.println("<td align=center><B>Products</B></td>");
	    }
	    else {
		out.println("<td align=center><B><a href=index?id=3>Products</a></B></td>");
	    }

	    if(id.equals("4")) {
		out.println("<td align=center><B>Logs</B></td>");
	    }
	    else {
		out.println("<td align=center><B><a href=index?id=4>Logs</a></B></td>");
	    }

	    if(id.equals("5")) {
		out.println("<td align=center><B>Images</B></td>");
	    }
	    else {
		out.println("<td align=center><B><a href=index?id=5>Images</a></B></td>");
	    }

	    out.println("<td align=center><B><a href="+request.getContextPath()+"/logout>Log Out</a></B></td>");

	    out.println("</tr>");
	    out.println("</table>");
	    out.println("<BR><BR>");
	    out.println("<table cellSpacing='0' cellPadding='0' border='0' align=center width=100% height=90%>");
	    out.println("<tr>");
	    out.println("<td align=center valign=top>");

	    try {
		RequestDispatcher rd = request.getRequestDispatcher("/main");
		rd.include(request,response);
	    }
	    catch (Exception e) {
	    }

	    out.println("</td>");
	    out.println("</tr>");
	    out.println("</table>");

	    out.println("<CENTER>");
	    out.println("<img src='/images/copy_right.gif' border='0'>");
	    out.println("</CENTER>");
	    out.println("</BODY>");
	    out.println("</HTML>");
	    return;
	}
	catch(IOException e) {
	    System.out.println("IndexServlet:Error:201:"+e);
	    return;
	}
	catch(Exception e) {
	    System.out.println("IndexServlet:Error:202:"+e);
	    return;
	}
    }

    public void doGet(HttpServletRequest request,  HttpServletResponse response)
    {
	doPost(request, response);
    }
}






